package com.cgnpc.scp.purchase.service.impl;

import com.cgnpc.cud.core.domain.AjaxResult;
import com.cgnpc.cuddemo.utils.IDHelper;
import com.cgnpc.scp.common.bean.CreateFileInfo;
import com.cgnpc.scp.common.bean.MyPageResult;
import com.cgnpc.scp.common.exception.ScpException;
import com.cgnpc.scp.common.pojo.UserInfo;
import com.cgnpc.scp.common.service.AppConstantService;
import com.cgnpc.scp.common.service.ExcelCustomTemplateService;
import com.cgnpc.scp.common.utils.*;
import com.cgnpc.scp.manager.mybatis.entity.DataDict;
import com.cgnpc.scp.manager.service.IDataDictService;
import com.cgnpc.scp.purchase.mybatis.entity.PurchaseCapital;
import com.cgnpc.scp.purchase.mybatis.entity.PurchaseCapitalExampleExtend;
import com.cgnpc.scp.purchase.mybatis.mapper.client.PurchaseCapitalMapper;
import com.cgnpc.scp.purchase.service.IPurchaseCapitalService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.session.SqlSession;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.math.BigDecimal;
import java.util.*;

@Service
public class PurchaseCapitalServiceImpl implements IPurchaseCapitalService {
    private static final Logger LOGGER = LoggerFactory.getLogger(PurchaseCapitalServiceImpl.class);

    @Autowired
    private MessageSource messageSource;

    @Autowired
    private SqlSession sqlSession;

    @Autowired
    private PurchaseCapitalMapper purchaseCapitalMapper;

    @Autowired
    private AppConstantService appConstantService;

    @Autowired
    private ExcelCustomTemplateService excelCustomTemplateService;

    @Autowired
    private IDataDictService dataDictService;

    /**
     * 创建查询Example
     *
     * @param reqEntity reqEntity
     * @param <T>       T
     * @return Example
     */
    private <T extends PurchaseCapital> PurchaseCapitalExampleExtend createQueryExample(T reqEntity) {
        // mybatis查询方式
        PurchaseCapitalExampleExtend queryExample = new PurchaseCapitalExampleExtend();

        // 设置排序字段
        // queryExample.setOrderByClause("order_index");

        // 设置查询条件

        // 年度
        if (reqEntity.getYear() != null) {
            // addCriterion("year =", value, "year");
            queryExample.setYearEqualTo(reqEntity.getYear());
        }

        // 合同号
        if (!StringUtil.isNullOrSpace(reqEntity.getContractNo())) {
            // addCriterion("contract_no like", value, "contractNo");
            queryExample.setContractNoLike(SqlUtil.valueJoinLikeBoth(reqEntity.getContractNo()));
        }

        // 合同名称
        if (!StringUtil.isNullOrSpace(reqEntity.getContractName())) {
            // addCriterion("contract_name like", value, "contractName");
            queryExample.setContractNameLike(SqlUtil.valueJoinLikeBoth(reqEntity.getContractName()));
        }

        // 申报人
        if (!StringUtil.isNullOrSpace(reqEntity.getDeclareUser())) {
            // addCriterion("declare_user like", value, "declareUser");
            queryExample.setDeclareUserLike(SqlUtil.valueJoinLikeBoth(reqEntity.getDeclareUser()));
        }

        // 类别
        if (reqEntity.getType() != null) {
            // addCriterion("type =", value, "type");
            queryExample.setTypeEqualTo(reqEntity.getType());
        }

        // 实际支付月份
        if (reqEntity.getMonthReal() != null) {
            // addCriterion("month_real =", value, "monthReal");
            queryExample.setMonthRealEqualTo(reqEntity.getMonthReal());
        }
        // 资金计划列表-------------多个id
        if (ListUtil.getListSizeWith0(reqEntity.getIdList()) > 0) {
            // queryExampleCriteria.andProjectNameLike(SqlUtil.valueJoinLikeBoth(reqEntity.getProjectName()));
            // addCriterion("project_name like", value, "projectName");
            queryExample.setIds(reqEntity.getIdList());
        }
        return queryExample;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public <T extends PurchaseCapital> AjaxResult saveOrUpdate(UserInfo loginUserInfo, Locale reqLocale, List<T> reqEntityList) {
        final String logInfo = "[PurchaseCapital_saveOrUpdate_UUID_" + UUID.randomUUID() + "]";
        AjaxResult ajaxResult = null;

        try {
            if (ListUtil.getListSizeWith0(reqEntityList) <= 0) {
                LOGGER.error("{}reqEntityListSize <= 0;", logInfo);
                return AjaxResultUtil.createI18nErrorDefaultMessage(reqLocale, messageSource);
            }

            Date nowDate = new Date();

            // begin 获取登录用户的信息
            String loginUserInfoUserId = loginUserInfo.getUserId();
            String loginUserInfoUserName = loginUserInfo.getUserName();
            // end 获取登录用户的信息

            T usedEntity = null;
            int saveRows = 0;
            int updateRows = 0;

            String reqId = null;

            for (T reqEntity : reqEntityList) {
                reqId = reqEntity.getId();

                if (StringUtil.isNullOrSpace(reqId)) {
                    // 保存
                    usedEntity = (T) new PurchaseCapital();
                    usedEntity.setId(IDHelper.uuidNew()); // 主键
                    usedEntity.setYear(reqEntity.getYear()); // 年度
                    usedEntity.setMonth(reqEntity.getMonth()); // 拟支付月份
                    usedEntity.setMonthReal(reqEntity.getMonthReal()); // 实际支付月份
                    usedEntity.setType(reqEntity.getType()); // 类别
                    usedEntity.setSapMonth(reqEntity.getSapMonth()); // sap收货月份
                    usedEntity.setContractNo(reqEntity.getContractNo()); // 合同号
                    usedEntity.setContractName(reqEntity.getContractName()); // 合同名称
                    usedEntity.setSupplier(reqEntity.getSupplier()); // 供应商
                    usedEntity.setPaymentCompany(reqEntity.getPaymentCompany()); // 支付公司
                    usedEntity.setCurrency(reqEntity.getCurrency()); // 币种
                    usedEntity.setPlanPrice(reqEntity.getPlanPrice()); // 计划支付金额
                    usedEntity.setPracticalPrice(reqEntity.getPracticalPrice()); // 实际支付金额
                    usedEntity.setDeclareUser(reqEntity.getDeclareUser()); // 申报人
                    usedEntity.setDescription(reqEntity.getDescription()); // 备注

                    // begin 公共字段
                    usedEntity.setCreateTime(nowDate);   // 创建时间
                    usedEntity.setCreateUser(loginUserInfoUserId); // 创建人员工号
                    usedEntity.setCreateUserName(loginUserInfoUserName); // 创建人姓名
                    usedEntity.setLastUpdateTime(nowDate); // 更新时间
                    usedEntity.setLastUpdateUser(loginUserInfoUserId); // 更新人员工号
                    usedEntity.setLastUpdateUserName(loginUserInfoUserName); // 更新人姓名
                    // end 公共字段

                    saveRows += purchaseCapitalMapper.insert(usedEntity);
                } else {
                    // 修改
                    usedEntity = (T) new PurchaseCapital();
                    usedEntity.setId(reqId); // 主键
                    usedEntity.setYear(reqEntity.getYear()); // 年度
                    usedEntity.setMonth(reqEntity.getMonth()); // 拟支付月份
                    usedEntity.setMonthReal(reqEntity.getMonthReal()); // 实际支付月份
                    usedEntity.setType(reqEntity.getType()); // 类别
                    usedEntity.setSapMonth(reqEntity.getSapMonth()); // sap收货月份
                    usedEntity.setContractNo(reqEntity.getContractNo()); // 合同号
                    usedEntity.setContractName(reqEntity.getContractName()); // 合同名称
                    usedEntity.setSupplier(reqEntity.getSupplier()); // 供应商
                    usedEntity.setPaymentCompany(reqEntity.getPaymentCompany()); // 支付公司
                    usedEntity.setCurrency(reqEntity.getCurrency()); // 币种
                    usedEntity.setPlanPrice(reqEntity.getPlanPrice()); // 计划支付金额
                    usedEntity.setPracticalPrice(reqEntity.getPracticalPrice()); // 实际支付金额
                    usedEntity.setDeclareUser(reqEntity.getDeclareUser()); // 申报人
                    usedEntity.setDescription(reqEntity.getDescription()); // 备注

                    // begin 公共字段
                    // usedEntity.setCreateTime(nowDate);   // 创建时间；不更新
                    // usedEntity.setCreateUser(loginUserInfoUserId); // 创建人员工号；不更新
                    // usedEntity.setCreateUserName(loginUserInfoUserName); // 创建人姓名；不更新
                    usedEntity.setLastUpdateTime(nowDate); // 更新时间
                    usedEntity.setLastUpdateUser(loginUserInfoUserId); // 更新人员工号
                    usedEntity.setLastUpdateUserName(loginUserInfoUserName); // 更新人姓名
                    // end 公共字段

                    updateRows += purchaseCapitalMapper.updateById(usedEntity);
                }
            }

            String strResultInfo = "保存" + saveRows + "行；修改" + updateRows + "行；";

            ajaxResult = AjaxResultUtil.createSuccessMessage(strResultInfo);
        } catch (Exception e) {
            LOGGER.error("{}saveOrUpdate.error;", logInfo, e);
            throw e;
        }

        return ajaxResult;
    }

    @Override
    public <T extends PurchaseCapital> MyPageResult<T> loadByPaging(T reqEntity) {
        // begin 分页查询
        // 第几页
        int pageNum = reqEntity.getPageNum();
        // 每页的数量
        int pageSize = reqEntity.getPageSize();
        // 创建Page对象，将pageNum，pageSize参数传入，必须位于数据库查询数据的语句之前，否则不生效
        com.github.pagehelper.Page<T> queryPage = PageHelper.startPage(pageNum, pageSize);

        // 创建queryExample
        PurchaseCapitalExampleExtend queryExample = createQueryExample(reqEntity);

        purchaseCapitalMapper.selectByExampleWithCustom(queryExample);

        // pagehelper分页插件的问题，需要创建PageInfo才能获取总记录数，queryPage.getResult()和dbEntityList是一样的
        PageInfo<T> pageResult = new PageInfo<>(queryPage.getResult());

        // 创建分页结果集对象
        MyPageResult<T> myPageResult = MyPageResultUtil.createMyPageResult(pageResult);
        // end 分页查询

        return myPageResult;
    }

    @Override
    public <T extends PurchaseCapital> T loadById(String id) {
        if (StringUtil.isNullOrSpace(id)) {
            return null;
        }

        return (T) purchaseCapitalMapper.selectById(id);
    }

    @Override
    public <T extends PurchaseCapital> CreateFileInfo exportExcel(T reqEntity) throws Exception {
        final String logInfo = "[exportExcel_UUID_" + UUID.randomUUID() + "]";
        CreateFileInfo createFileInfo = null;

        try {
            // 创建queryExample
            PurchaseCapitalExampleExtend queryExample = createQueryExample(reqEntity);

            // mappedStatementNamespace为mybatis生成的mapper.xml中的命名空间
            String mappedStatementNamespace = "com.cgnpc.scp.purchase.mybatis.mapper.client.PurchaseCapitalMapper";
            // mappedStatementMethod为mybatis生成的mapper.xml中的方法
            String mappedStatementMethod = "selectByExampleWithCustom";
            // mappedStatementId为具体指向的方法
            String mappedStatementId = mappedStatementNamespace + "." + mappedStatementMethod;

            // mappedStatementParameter可以为mybatis自动生成的XxxExample实体类，例如UserExample
            Object mappedStatementParameter = queryExample;
            String exportDictGroupKey = DataDictUtil.DICT_GROUP_KEY_WITH_PURCHASECAPITAL_EXPORTEXCEL;

            createFileInfo = excelCustomTemplateService.createXlsxToWebDir(
                    sqlSession
                    , mappedStatementId
                    , mappedStatementParameter
                    , exportDictGroupKey
            );
        } catch (Exception e) {
            LOGGER.error("{}error;", logInfo, e);
            throw e;
        }

        return createFileInfo;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public <T extends PurchaseCapital> AjaxResult importFromExcel(UserInfo loginUserInfo, Locale reqLocale, MultipartFile reqFile) throws Exception {
        final String logInfo = "[importFromExcel_UUID_" + UUID.randomUUID() + "]";
        AjaxResult ajaxResult = null;
        XSSFWorkbook workbook = null;
        InputStream reqFileInputStream = null;

        try {
            if (reqFile == null) {
                return AjaxResultUtil.createErrorMessage("文件不存在");
            }

            boolean reqFileEmpty = reqFile.isEmpty();
            String reqFileName = reqFile.getName();
            String reqFileOriginalFilename = reqFile.getOriginalFilename();

            LOGGER.info("{}reqFileEmpty:{};reqFileName:{};reqFileOriginalFilename:{};"
                    , logInfo
                    , reqFileEmpty, reqFileName, reqFileOriginalFilename
            );

            if (!reqFileOriginalFilename.toLowerCase().endsWith(".xlsx".toLowerCase(Locale.ENGLISH))) {
                LOGGER.error("{}只支持.xlsx文件。", logInfo);
                return AjaxResultUtil.createErrorMessage("只支持.xlsx文件", null);
            }

            // begin 查询数据字典信息
            List<DataDict> dbDataDictListWithType = dataDictService.queryByDictGroupKey(DataDictUtil.DICT_GROUP_KEY_WITH_PURCHASECAPITAL_TYPE);
            List<DataDict> dbDataDictListWithPaymentCompany = dataDictService.queryByDictGroupKey(DataDictUtil.DICT_GROUP_KEY_WITH_PURCHASECAPITAL_PAYMENT_COMPANY);
            List<DataDict> dbDataDictListWithCurrency = dataDictService.queryByDictGroupKey(DataDictUtil.DICT_GROUP_KEY_WITH_PURCHASECAPITAL_CURRENCY);

            Map<String, DataDict> usedDataDictTextWithTypeMap = new HashMap<>();
            Map<String, DataDict> usedDataDictTextWithPaymentCompanyMap = new HashMap<>();
            Map<String, DataDict> usedDataDictTextWithCurrencyMap = new HashMap<>();

            if (ListUtil.getListSizeWith0(dbDataDictListWithType) > 0) {
                String dbDataDictDictText = null;

                for (DataDict dbDataDict : dbDataDictListWithType) {
                    dbDataDictDictText = dbDataDict.getDictText();

                    if (usedDataDictTextWithTypeMap.containsKey(dbDataDictDictText)) {
                        throw new ScpException("导入Excel失败，数据字典组key（" + DataDictUtil.DICT_GROUP_KEY_WITH_PURCHASECAPITAL_TYPE + "）"
                                + "下，其中某个数据字典文本配置存在重复，当前文本为：" + dbDataDictDictText
                        );
                    }

                    usedDataDictTextWithTypeMap.put(dbDataDictDictText, dbDataDict);
                }
            }

            if (ListUtil.getListSizeWith0(dbDataDictListWithPaymentCompany) > 0) {
                String dbDataDictDictText = null;

                for (DataDict dbDataDict : dbDataDictListWithPaymentCompany) {
                    dbDataDictDictText = dbDataDict.getDictText();

                    if (usedDataDictTextWithTypeMap.containsKey(dbDataDictDictText)) {
                        throw new ScpException("导入Excel失败，数据字典组key（" + DataDictUtil.DICT_GROUP_KEY_WITH_PURCHASECAPITAL_PAYMENT_COMPANY + "）"
                                + "下，其中某个数据字典文本配置存在重复，当前文本为：" + dbDataDictDictText
                        );
                    }

                    usedDataDictTextWithPaymentCompanyMap.put(dbDataDictDictText, dbDataDict);
                }
            }

            if (ListUtil.getListSizeWith0(dbDataDictListWithCurrency) > 0) {
                String dbDataDictDictText = null;

                for (DataDict dbDataDict : dbDataDictListWithCurrency) {
                    dbDataDictDictText = dbDataDict.getDictText();

                    if (usedDataDictTextWithTypeMap.containsKey(dbDataDictDictText)) {
                        throw new ScpException("导入Excel失败，数据字典组key（" + DataDictUtil.DICT_GROUP_KEY_WITH_PURCHASECAPITAL_CURRENCY + "）"
                                + "下，其中某个数据字典文本配置存在重复，当前文本为：" + dbDataDictDictText
                        );
                    }

                    usedDataDictTextWithCurrencyMap.put(dbDataDictDictText, dbDataDict);
                }
            }
            // end 查询数据字典信息

            reqFileInputStream = reqFile.getInputStream();
            workbook = new XSSFWorkbook(reqFileInputStream);
            Sheet sheet = workbook.getSheetAt(0);

            Iterator<Row> itRow = sheet.rowIterator();
            int rowIndex = 0;
            Row row = null;
            Cell cell000 = null;
            Cell cell001 = null;
            Cell cell002 = null;
            Cell cell003 = null;
            Cell cell004 = null;
            Cell cell005 = null;
            Cell cell006 = null;
            Cell cell007 = null;
            Cell cell008 = null;
            Cell cell009 = null;
            Cell cell010 = null;
            Cell cell011 = null;
            Cell cell012 = null;
            Cell cell013 = null;
            String cellValue000 = null;
            String cellValue001 = null;
            String cellValue002 = null;
            String cellValue003 = null;
            String cellValue004 = null;
            String cellValue005 = null;
            String cellValue006 = null;
            String cellValue007 = null;
            String cellValue008 = null;
            String cellValue009 = null;
            String cellValue010 = null;
            String cellValue011 = null;
            String cellValue012 = null;
            String cellValue013 = null;

            final List<T> reqEntityList = new ArrayList<>();
            T reqEntity = null;
            // SimpleDateFormat sdfYyyymmddHhmmss = new SimpleDateFormat(DateUtil.KEY_YYYYMMDD_HHMMSS_INCLUDE_SPLIT_CHAR);
            // SimpleDateFormat sdfYyyymmdd = new SimpleDateFormat(DateUtil.KEY_YYYYMMDD_INCLUDE_SPLIT_CHAR);

            while (itRow.hasNext()) {
                row = itRow.next();

                // 第1行为标题
                if (rowIndex++ <= 0) {
                    continue;
                }

                // 流程实例id
                // 合同号
                // 合同名称
                // 物项序号
                // 项目
                // 物项（服务）名称
                // 技术规格
                // 数量
                // 单位
                // 要求到货时间
                // 计划验收完成时间

                cell000 = row.getCell(0);
                cell001 = row.getCell(1);
                cell002 = row.getCell(2);
                cell003 = row.getCell(3);
                cell004 = row.getCell(4);
                cell005 = row.getCell(5);
                cell006 = row.getCell(6);
                cell007 = row.getCell(7);
                cell008 = row.getCell(8);
                cell009 = row.getCell(9);
                cell010 = row.getCell(10);
                cell011 = row.getCell(11);
                cell012 = row.getCell(12);
                cell013 = row.getCell(13);

                cellValue000 = ExcelUtil.getCellValue(cell000);
                cellValue001 = ExcelUtil.getCellValue(cell001);
                cellValue002 = ExcelUtil.getCellValue(cell002);
                cellValue003 = ExcelUtil.getCellValue(cell003);
                cellValue004 = ExcelUtil.getCellValue(cell004);
                cellValue005 = ExcelUtil.getCellValue(cell005);
                cellValue006 = ExcelUtil.getCellValue(cell006);
                cellValue007 = ExcelUtil.getCellValue(cell007);
                cellValue008 = ExcelUtil.getCellValue(cell008);
                cellValue009 = ExcelUtil.getCellValue(cell009);
                cellValue010 = ExcelUtil.getCellValue(cell010);
                cellValue011 = ExcelUtil.getCellValue(cell011);
                cellValue012 = ExcelUtil.getCellValue(cell012);
                cellValue013 = ExcelUtil.getCellValue(cell013);

                reqEntity = (T) new PurchaseCapital();
                reqEntityList.add(reqEntity);

                // "年度（数字）"
                // "拟支付月份（数字；1-12月；）"
                // "实际支付月份（数字；1-12月；）"
                // 类别
                // "SAP收货月份（数字；1-12月；）"
                // 合同号
                // 合同名称
                // 供应商
                // 支付公司
                // "币种（当前只支持人民币，值请填写CNY）"
                // "计划支付金额（当前只支持人民币，其他货币请填写等值的人民币）"
                // "实际支付金额（当前只支持人民币，其他货币请填写等值的人民币）"
                // 申报人
                // 备注

                String reqType = cellValue003; // 类别
                String reqPaymentCompany = cellValue008; // 支付公司
                String reqCurrency = cellValue009; // 币种

                Integer usedType = null;
                String usedPaymentCompany = null;
                String usedCurrency = null;

                if (!usedDataDictTextWithTypeMap.containsKey(reqType)) {
                    throw new ScpException("导入Excel中的“类别”文本不正确，请填写数据字典组key（" + DataDictUtil.DICT_GROUP_KEY_WITH_PURCHASECAPITAL_TYPE + "）"
                            + "下的具体数据字典文本"
                    );
                } else {
                    usedType = Integer.valueOf(usedDataDictTextWithTypeMap.get(reqType).getDictKey());
                }

                if (!usedDataDictTextWithPaymentCompanyMap.containsKey(reqPaymentCompany)) {
                    throw new ScpException("导入Excel中的“支付公司”文本不正确，请填写数据字典组key（" + DataDictUtil.DICT_GROUP_KEY_WITH_PURCHASECAPITAL_PAYMENT_COMPANY + "）"
                            + "下的具体数据字典文本"
                    );
                } else {
                    usedPaymentCompany = usedDataDictTextWithPaymentCompanyMap.get(reqPaymentCompany).getDictKey();
                }

                if (!usedDataDictTextWithCurrencyMap.containsKey(reqCurrency)) {
                    throw new ScpException("导入Excel中的“支付公司”文本不正确，请填写数据字典组key（" + DataDictUtil.DICT_GROUP_KEY_WITH_PURCHASECAPITAL_CURRENCY + "）"
                            + "下的具体数据字典文本"
                    );
                } else {
                    usedCurrency = usedDataDictTextWithCurrencyMap.get(reqCurrency).getDictKey();
                }

                reqEntity.setYear(NumberUtil.parseStringToIntegerWithNull(cellValue000));
                reqEntity.setMonth(NumberUtil.parseStringToIntegerWithNull(cellValue001));
                reqEntity.setMonthReal(NumberUtil.parseStringToIntegerWithNull(cellValue002));
                reqEntity.setType(usedType);
                reqEntity.setSapMonth(NumberUtil.parseStringToIntegerWithNull(cellValue004));
                reqEntity.setContractNo(cellValue005);
                reqEntity.setContractName(cellValue006);
                reqEntity.setSupplier(cellValue007);
                reqEntity.setPaymentCompany(usedPaymentCompany);
                reqEntity.setCurrency(usedCurrency);
                reqEntity.setPlanPrice(new BigDecimal(cellValue010));
                reqEntity.setPracticalPrice(new BigDecimal(cellValue011));
                reqEntity.setDeclareUser(cellValue012);
                reqEntity.setDescription(cellValue013);

                if (ListUtil.getListSizeWith0(reqEntityList) >= SqlUtil.INSERT_BATCH_MAX_ROWS) {
                    saveOrUpdate(loginUserInfo, reqLocale, reqEntityList);
                    reqEntityList.clear();
                }
            }

            if (ListUtil.getListSizeWith0(reqEntityList) > 0) {
                saveOrUpdate(loginUserInfo, reqLocale, reqEntityList);
                reqEntityList.clear();
            }

            ajaxResult = AjaxResultUtil.createSuccessMessage("保存成功");
        } catch (Exception e) {
            LOGGER.error("{}error;", logInfo, e);
            throw e;
        } finally {
            IOUtil.closeStream(reqFileInputStream);
            ExcelUtil.closeWorkbook(workbook);
        }

        return ajaxResult;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public <T extends PurchaseCapital> AjaxResult del(UserInfo loginUserInfo, Locale reqLocale, T reqEntity) {
        final String logInfo = "[PurchaseCapital_del_UUID_" + UUID.randomUUID() + "]";
        AjaxResult ajaxResult = null;

        try {
            List<String> reqIdList = reqEntity.getIdList();

            if (ListUtil.getListSizeWith0(reqIdList) <= 0) {
                return AjaxResultUtil.createI18nErrorDefaultMessage(reqLocale, messageSource);
            }

            int delRows = purchaseCapitalMapper.deleteBatchIds(reqIdList);

            String strResultInfo = "删除" + delRows + "行；";

            ajaxResult = AjaxResultUtil.createSuccessMessage(strResultInfo);
        } catch (Exception e) {
            LOGGER.error("{}del.error;", logInfo, e);
            throw e;
        }

        return ajaxResult;
    }
}
